source /home/oracle/.bash_profile
sqlplus / as sysdba << eof |grep 'LOG_ARCHIVE_DEST' > /tmp/format1_`date +%F`.txt
set linesize 300;
set pagesize 300;
column dest_name format a25
column destination format a50
column type format a10
column database_mode format a20
column recovery_mode format a30
column protection_mode format a30
column SRL format a5
column GAP_STATUS format a15
select dest_name, type, database_mode,SRL from V\$ARCHIVE_DEST_STATUS;
eof

sqlplus / as sysdba << eof |grep 'LOG_ARCHIVE_DEST' > /tmp/format2_`date +%F`.txt
set linesize 300;
set pagesize 300;
column dest_name format a25
column destination format a50
column type format a10
column database_mode format a20
column recovery_mode format a30
column protection_mode format a30
column SRL format a5
column GAP_STATUS format a15
select dest_name, destination from V\$ARCHIVE_DEST_STATUS;
eof

sqlplus / as sysdba << eof |grep 'LOG_ARCHIVE_DEST' > /tmp/format3_`date +%F`.txt
set linesize 300;
set pagesize 300;
column dest_name format a25
column destination format a50
column type format a10
column database_mode format a20
column recovery_mode format a30
column protection_mode format a30
column SRL format a5
column GAP_STATUS format a15
select dest_name, GAP_STATUS from V\$ARCHIVE_DEST_STATUS;
eof

sqlplus / as sysdba << eof |grep 'LOG_ARCHIVE_DEST' > /tmp/format4_`date +%F`.txt
set linesize 300;
set pagesize 300;
column dest_name format a25
column destination format a50
column type format a10
column database_mode format a20
column recovery_mode format a30
column protection_mode format a30
column SRL format a5
column GAP_STATUS format a15
select dest_name, recovery_mode from V\$ARCHIVE_DEST_STATUS;
eof

sqlplus / as sysdba << eof |grep 'LOG_ARCHIVE_DEST' > /tmp/format5_`date +%F`.txt
set linesize 300;
set pagesize 300;
column dest_name format a25
column destination format a50
column type format a10
column database_mode format a20
column recovery_mode format a30
column protection_mode format a30
column SRL format a5
column GAP_STATUS format a15
select dest_name,  protection_mode from V\$ARCHIVE_DEST_STATUS;
eof


# dest_name, type, database_mode, SRL, GAP_STATUS, destination, recovery_mode, protection_mode
while read line
do
destname=`echo $line|awk '{print $1}'`
denation=$(grep -w $destname /tmp/format2_`date +%F`.txt |awk '{print $2}')
stat=$(grep -w $destname /tmp/format3_`date +%F`.txt |awk '{print $2}')
recover=$(grep -w $destname /tmp/format4_`date +%F`.txt |awk '{$1="";print}'|sed -e 's/^[ ]*//g')
mode=$(grep -w $destname /tmp/format5_`date +%F`.txt |awk '{$1="";print}'|sed -e 's/^[ ]*//g')
f=`echo $line|awk 'BEGIN{ OFS="&" } {print $1,$2,$3,$4}'`
echo "$f&$stat&$denation&$recover&$mode"
done< /tmp/format1_`date +%F`.txt
if [ $? -ne 0 ];then
    echo "script_execute_error!" && exit 1
else
    echo "script_execute_success!"
fi